package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DtsCommentServiceImpl implements DtsCommentService {
    @Autowired
    DtsCommentMapper commentMapper;
    @Override
    public IPage<DtsComment> findPage(Integer page, Integer limit, String sort, String desc, Integer userId, Integer goodsId, List<Integer> brands) {
        IPage<DtsComment> ipage = new Page<>(page,limit);
        QueryWrapper<DtsComment> qw = new QueryWrapper<>();
        if(userId!=null){
            qw.like("c.user_id",userId);
        }

        if(goodsId!=null){
            qw.like("c.value_id",goodsId);
        }

        if(brands!=null&&brands.size()!=0){
            qw.in("g.brand_id",brands);
        }

        commentMapper.selectCommentPage(ipage,qw);
        return ipage;
    }

    @Override
    public void delete(DtsComment dtsComment) {
        dtsComment.setDeleted(true);
        commentMapper.updateById(dtsComment);
    }
}
